/*
 * Test program for 8x8 LED matrix (single color) and two shift registor
 * test No.2
 *
 * HISTORY
 * 2010/8/16  New
 * 2010/8/22  modify pattern
 *
 */

/*
 * Copyright (c) 2010 elekid
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

// for 7 segments x 4 display

int CLOCK_PIN =2;
int DATA_PIN  =3;

byte PATTERN[8] = {
B10110000,
B10101010,
B11101100,
B10101010,
B11111010,
B10101010,
B11111110,
B10101010,
};

#define WAITS 20


void setup()
{

  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN,  OUTPUT);

}
void loop()
{ 
  for ( int i = 0 ; i < 8 ; i++) {
    for ( int j = 0 ; j < 8 ; j++) {
      int k;
      if ( i==0 || i==2 || i==4 || i==6) {
        k=j;
      } else {
        k= 7 - j ;
      }
      matrix_clear();
      matrix_on(i,k);
      delay(WAITS);
    }
  }
  for ( int i = 7 ; i >= 0 ; i--) {
    for ( int j = 7 ; j >=0 ; j--) {
      int k;
      if ( i==0 || i==2 || i==4 || i==6) {
        k=j;
      } else {
        k= 7 - j ;
      }
      matrix_clear();
      matrix_on(i,k);
      delay(WAITS);
    }
  }
}

void matrix_clear(){
  // not implemented.
}

void matrix_on(int i,int j) {
  byte b=0xFF ^ 1 << j;
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, b);
  if ( i == 0) {
    b = 1 ;
  } else {
    b = 1 << i;
  }
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, b);
  
}
